<?php
/**
 * @name		Add News
 * @author		C. Hazekamp
 * @copyright	C. Hazekamp
 * @version     2.0.0
 * @date   		13-6-2012 11:22:37
 * @access		private
 * @filesource	/modules/news/admin/addnews.php
 * @package     ObbyCMS 2.0
 */
 
if (!defined('PUBLIC_HTML'))
{
	exit;
}

// Submission check
$submit = isset($_POST['submit']) ? true : false;

// Post news
if ($submit)
{
	$post = array();
	$post['category']		= (int) 	$_POST['category'];
	$post['language']		= (string)	'en';
	$post['carrousel']		= (int)		$_POST['carrousel'];
	$post['highlight']		= (int) 	$_POST['highlight'];
	$post['media_thumb']	= (int)		$_POST['media_thumb'];
	$post['media_normal']	= (int)		$_POST['media_normal'];
	$post['media_highlight']= (int)		$_POST['media_highlight'];
	$post['title']			= (string)	$_POST['title'];
	$post['message']		= (string)	nl2br($_POST['message']);
	$post['datetime']		= (string)	date('Y-m-d H:i:s');
	$post['user_id']		= (int)		$user->data['usr_id'];
	$post['user_ip']		= (string)	$_SERVER['REMOTE_ADDR'];
	$post['replies']		= (int)		$_POST['replies'];
	$post['active']			= (int)		$_POST['active'];
	$addnews = $db->sql_insert_row(TABLE_NEWS, $post, 'news_');
	
	unset($post);
	$post['news_group_id'] = (int) $addnews;
	$db->sql_update_row(TABLE_NEWS, $post, 'news_id', $post['news_group_id']);
	redirect('cms.php?m=news');
	exit;
}


// Find categories
try
{
	foreach ($db->sql_get(TABLE_NEWS_CATEGORIES, '*', 'cat_language', 'en') as $row_categories)
	{
		$tpl->zone('categories', array(
			'ID'	=> (int) 	$row_categories['cat_group_id'],
			'TITLE'	=> (string) $row_categories['cat_title']
		));
	}
}
catch (ErrorHandler $e)
{
	$e->print_error('There was an error while fetching the categories.');
}

?>